package com.hycc.jsoup;

import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
import java.net.URL;

public class JsoupDemo1 {
    public static void main(String[] args) {
        try {
            //测试网址
            URL url = new URL("https://voice.hupu.com/nba"); //test

            //注意导入的Document包是不是Jsoup的
            Document dom = Jsoup.parse(url,2000);
            Elements elements = dom.select("div.news-list > ul > li > div.list-hd > h4 > a");

            //遍历元素
            for (Element element : elements) {
                System.out.println(element.ownText());
                System.out.println(element.attr("href"));
            }

        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
